//
//  PxReaderView.h
//  Express
//
//  Created by 泰然财富 on 15/7/28.
//  Copyright (c) 2015年 泰然财富. All rights reserved.
//

#import "PxTableViewCell.h"
#import "LLSmallUtil.h"
#import "UIView+Sizes.h"

@implementation PxTableViewCell {
    BOOL isEditing;
    NSDictionary *data;
    BOOL isSeleted;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        isEditing = NO;
        isSeleted = NO;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)initViewWithData:(NSDictionary *)dic
{
    data = dic;
    self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    self.textLabel.text = dic[@"deliveryAddress"];
    self.textLabel.textColor = [UIColor colorWithHTMLStr:@"444444"];
    self.textLabel.font = [UIFont systemFontOfSize:15];
    UIImage *img = [UIImage imageNamed:@"Images/umCheck"];
    UIColor *color = [UIColor colorWithHTMLStr:@"e78404"];
    NSString *noticeStatusName = @"待通知";
    if ([dic[@"noticeStatus"] boolValue]) {
        color = [UIColor colorWithHTMLStr:@"666666"];
        if (isEditing)
            self.userInteractionEnabled = NO;
        img = [UIImage imageNamed:@"Images/notCheck"];
        noticeStatusName = @"已通知";
    }
    self.detailTextLabel.text = noticeStatusName;
    self.imageView.image = img;
    self.detailTextLabel.textColor = color;
    self.detailTextLabel.font = [UIFont systemFontOfSize:12];
    
    if (isEditing) {
        self.imageView.hidden = NO;
        self.textLabel.left = 15 + self.imageView.width + 5;
    } else {
        self.imageView.hidden = YES;
        self.textLabel.left = 15;
    }
    
    if (isSeleted) {
        self.imageView.image = [UIImage imageNamed:@"Images/Check"];
    }
    
    UIView *seperator = [[UIView alloc] initWithFrame:CGRectMake(15, 0, self.contentView.width, 1)];
    seperator.backgroundColor = [UIColor colorWithHTMLStr:@"d6d6d6"];
    seperator.top = self.contentView.bottom - 1;
    [self.contentView addSubview:seperator];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    if (data)
        [self initViewWithData:data];
}

-(void)reload:(BOOL)isEdited WithData:(NSDictionary *)dic
{
    isEditing = isEdited;
    [self initViewWithData:dic];
}

-(void)selecteView
{
    isSeleted = !isSeleted;
    [self initViewWithData:data];
}

-(void)resetSeletedFlag
{
    isSeleted = NO;
}

@end